import json
import math
import re
import traceback

from re_common.baselibrary.utils.basedict import BaseDicts
from re_common.baselibrary.utils.baseurl import BaseUrl

from apps.crawler_platform.core_platform.core_sql import CoreSqlValue
from apps.crawler_platform.core_platform.g_model import DealModel, CallBackModel, JournalListModel, JournalIssueModel, \
    JournalArticleModel, DealInsertModel, JournalHomeModel, DealUpdateModel, OperatorSqlModel

__all__ = ["para_key_callback",
           "cnkijournal_cnkijournallist_callback",
           "cnkijournal_cnkiissue_callback",
           "cnkijournal_cnkinet1st_callback",
           "cnkijournal_cnkinet1starticle_callback",
           "cnkijournal_cnkiarticle_callback",
           "cnkijournal_cnkiclasshome_callback",
           "cnkijournal_cnkiqkhome_callback",
           "cnkijournal_cnkiqkclasshome_callback"]


def para_key_callback(dicts):
    if isinstance(dicts, dict):
        for k, v in dicts.items():
            if not isinstance(v, (list, tuple, dict)):
                if k == "key_name":
                    v = v.replace("：", "").replace(":", "").strip()
                    v = re.sub(r"\(\d+\)", "", v)
                    dicts[k] = v
            else:
                para_key_callback(v)
    elif isinstance(dicts, (list, tuple)):
        for i in range(len(dicts)):
            para_key_callback(dicts[i])


def cnkijournal_cnkijournallist_callback(callmodel: CallBackModel[JournalListModel]) -> DealModel:
    result = DealModel()
    journal_json_dicts = {}
    dicts = {
        "目前状态": "state",
        "曾用刊名": "journal_name_used",
        "主办单位": "publisher",
        "出版周期": "type_name",
        "ISSN": "issn",
        "CN": "cnno",
        "出版地": "pub_place",
        "语种": "language",
        "开本": "book_size",
        "邮发代号": "sem_code",
        "创刊时间": "create_date",
        "专辑名称": "special_name",
        "专题名称": "subject_name",
        "来源数据库": "source_db",
        "出版文献量": "article_count",
        "总下载次数": "down_cnt",
        "总被引次数": "cited_cnt",
        "复合影响因子": "cnki_impact_fh",
        "综合影响因子": "cnki_impact_zh",

    }
    para_dicts = callmodel.para_dicts
    task_info = callmodel.redis_all.parse_dict["1_1"].task_info
    journal_rawid = callmodel.sql_model.journal_rawid
    info_dicts = {"task_name": task_info.task_name,
                  "task_tag": task_info.task_tag,
                  "journal_rawid": journal_rawid,
                  "sub_db_id": callmodel.sql_model.sub_db_id,
                  "task_tag_next": task_info.task_tag_next}
    para_dicts = para_dicts["data"]
    para_key_callback(para_dicts)
    for k, v in para_dicts.items():
        if k == "1_1":
            for k, v in para_dicts[k].items():
                if k in ["cnki_exclusive", "individual_issue", "first_launch"]:
                    if v == "":
                        v = 0
                    else:
                        v = 1
                    journal_json_dicts[k] = v
                elif k == "qk_info":
                    for item in v["children"]:
                        k = item["key_name"]
                        v = item["value"]
                        if k in dicts.keys():
                            k = dicts[k]
                            journal_json_dicts[k] = v
                        else:
                            result.other_dicts.update({k: v})
                else:
                    if k in dicts.values():
                        journal_json_dicts[k] = v
                    else:
                        result.other_dicts.update({k: v})
            for k in dicts.keys():
                if k not in journal_json_dicts.keys():
                    result.null_dicts.update({k: ""})
        if k == "1_2":
            issue_json = {}
            insert = DealInsertModel()
            insert.insert_pre = CoreSqlValue.insert_ig_it
            for item in para_dicts[k]["year_issue"]["children"]:
                year = item["year"]
                issue_list = item["issue"].split(";")
                for i in issue_list:
                    num = i[len('No.'):]
                    temp = info_dicts.copy()
                    temp["task_tag"] = temp["task_tag_next"].split(";")[0]
                    del temp["task_tag_next"]
                    temp.update(
                        {'pub_year': year, 'num': num, 'issue_json': json.dumps(issue_json, ensure_ascii=False)})
                    insert.lists.append(temp)
            result.next_dicts.insert.append(insert)
                    # result.next_dicts["insert_ig"]["lists"].append(temp)
            temp = info_dicts.copy()
            temp["task_tag"] = temp["task_tag_next"].split(";")[-1]
            del temp["task_tag_next"]
            temp.update({'pub_year': "", 'num': "", 'issue_json': json.dumps(issue_json, ensure_ascii=False)})
            insert = DealInsertModel()
            insert.lists.append(temp)
            insert.insert_pre = CoreSqlValue.replace_it
            result.next_dicts.insert.append(insert)
            # result.next_dicts["replace_"]["lists"].append(temp)

    qk_dicts = json.loads(callmodel.sql_model.journal_json)
    qk_dicts.update(journal_json_dicts)
    result.befor_dicts.update['journal_json'] = json.dumps(qk_dicts, ensure_ascii=False)
    # result.befor_dicts.update({"journal_json": json.dumps(qk_dicts, ensure_ascii=False)})

    return result


def cnkijournal_cnkiissue_callback(callmodel: CallBackModel[JournalIssueModel]) -> DealModel:
    result = DealModel()
    para_dicts = callmodel.para_dicts

    task_info = callmodel.redis_all.parse_dict["1_1"].task_info
    sql_model = callmodel.sql_model
    info_dicts = {"task_name": task_info.task_name,
                  "task_tag": task_info.task_tag,
                  "task_tag_next": task_info.task_tag_next,
                  "journal_rawid": sql_model.journal_rawid,
                  "pub_year": sql_model.pub_year,
                  "num": sql_model.num,
                  "sub_db_id": sql_model.sub_db_id
                  }

    articleCount = para_dicts["data"]["1_1"]["articleCount"]
    result.befor_dicts.update["articlecount"] = articleCount
    result.befor_dicts.update["page"] = "1"
    list_col = para_dicts["data"]["1_1"]["issue_info"]["children"]
    insert = DealInsertModel()
    insert.insert_pre = CoreSqlValue.insert_ig_it
    for item in list_col:
        column_info = item["col"]
        for item1 in item["children"]:
            url = item1["url"]
            title = item1["title"]
            page_info = item1["pageline"]
            if_html_fulltext = item1["if_html_fulltext"]
            if if_html_fulltext == 'HTML阅读':
                if_html_fulltext = 1
            else:
                if_html_fulltext = 0
            rawid = BaseUrl.urlQuery2Dict(url)["filename"]
            if not rawid:
                continue
                # 在这里报告一个错误
            temp = info_dicts.copy()
            temp["task_tag"] = temp["task_tag_next"]
            del temp["task_tag_next"]
            temp["column_info"] = column_info
            temp["url"] = url
            temp["title"] = title
            temp["page_info"] = page_info
            temp["if_html_fulltext"] = if_html_fulltext
            temp["rawid"] = rawid

            new_temp = {}
            new_temp["rawid"] = temp["rawid"]
            new_temp["task_tag"] = temp["task_tag"]
            new_temp["task_name"] = temp["task_name"]
            new_temp["sub_db_id"] = temp["sub_db_id"]
            del temp["rawid"]
            del temp["task_tag"]
            del temp["task_name"]
            del temp["sub_db_id"]

            new_temp["article_info_json"] = json.dumps(temp, ensure_ascii=False)
            insert.lists.append(new_temp)

    result.next_dicts.insert.append(insert)
    # result.next_dicts["insert_ig"]["lists"].append(new_temp)

    return result


def cnkijournal_cnkinet1st_callback(callmodel: CallBackModel[JournalIssueModel]) -> DealModel:
    result = DealModel()
    task_info = callmodel.redis_all.parse_dict["1_1"].task_info
    sql_model = callmodel.sql_model
    info_dicts = {"task_name": task_info.task_name,
                  "task_tag": task_info.task_tag_next,
                  "journal_rawid": sql_model.journal_rawid,
                  "sub_db_id": sql_model.sub_db_id
                  }

    page_dicts = callmodel.para_dicts["1_1"]["data"]
    articlecount = None
    for page, item_dict in page_dicts.items():
        articlecount = item_dict["input"]
        for items in item_dict["article"]["children"]:
            url = items["href"]
            dictss = BaseUrl.urlQuery2Dict(url)
            rawid = dictss["url"]  # 一个新的id
            rawid_alt = dictss["filename"]
            items["rawid_alt"] = rawid_alt
            items["journal_rawid"] = info_dicts["journal_rawid"]
            temp_info = info_dicts.copy()
            del temp_info["journal_rawid"]
            temp_info["rawid"] = rawid
            temp_info["article_info_json"] = json.dumps(items, ensure_ascii=False)
            insert = DealInsertModel()
            insert.lists.append(temp_info)
            insert.insert_pre = CoreSqlValue.replace_it
            result.next_dicts.insert.append(insert)
            # result.next_dicts["replace_"]["lists"].append(temp_info)
    # result.next_dicts["replace_"]["replace"] = CoreSqlValue.replace_it
    if articlecount:
        # 因为是0页开始的，且自动翻页会加1 所以这里要减1
        page = math.ceil(int(articlecount) / 20)
        page = page - 1
        result.befor_dicts.update["page"] = str(page)
        result.befor_dicts.update["articlecount"] = str(articlecount)
        result.code_dicts = {
            "1_1": {"max_page": str(page)}

        }
    return result


def cnkijournal_cnkinet1starticle_callback(callmodel: CallBackModel[JournalIssueModel]) -> DealModel:
    result = DealModel()
    # 注意 这里传入的是down_model
    html_dicts = callmodel.para_dicts
    try:
        dicts = html_dicts["down_dict"]["1_1"]["state_dict"]
        if dicts["code"] == 200:
            result.befor_dicts.update["state"] = 1
        else:
            result.befor_dicts.update["state"] = dicts["code"]
    except:
        result.befor_dicts.update["err_msg"] = traceback.format_exc()
        result.befor_dicts.update_no_placeholder.update({"failcount": "failcount+1"})

    try:
        dicts = html_dicts["down_dict"]["2_1"]["state_dict"]
        if dicts["code"] == 200:
            result.befor_dicts.update["oversea"] = 1
        else:
            result.befor_dicts.update["oversea"] = dicts["code"]

    except:
        result.befor_dicts.update["err_msg"] = traceback.format_exc()
        result.befor_dicts.update_no_placeholder.update({"oversea_failcount": "oversea_failcount+1"})
    return result


def cnkijournal_cnkiarticle_callback(callmodel: CallBackModel[JournalArticleModel]) -> DealModel:
    result = DealModel()
    article_info_json = callmodel.sql_model.article_info_json
    article_info_dict = json.loads(article_info_json)
    # 解析返回的数据

    p_data = callmodel.para_dicts["data"]
    result.code_dicts = {}
    if "1_1" in p_data:
        info = p_data["1_1"]
        article_info_dict.update(info)
    if "1_2" in p_data:
        info_str = p_data["1_2"]["html"]
        info = json.loads(info_str)
        REFERENCE = info["REFERENCE"]
        CITING = info["CITING"]
        article_info_dict.update({"refcount": REFERENCE, "citecount": CITING})
    if "1_3.first_page" in p_data:
        result.code_dicts["1_3"] = {}
        showpage = p_data["1_3.first_page"]["showpage"]
        pcount = p_data["1_3.first_page"]["pcount"]
        if showpage:

            for item in showpage.split(";"):
                matObj = re.search(r"ShowPage\('(\d+)','([^']+)',", item)
                if not matObj:
                    continue
                pageTotal = math.ceil(int(matObj.group(1)) / 10)
                CurDBCode = matObj.group(2)
                result.code_dicts["1_3"][CurDBCode] = {"params": {"curdbcode": CurDBCode}, "max_page": pageTotal}
    if "1_4.first_page" in p_data:
        result.code_dicts["1_4"] = {}
        showpage = p_data["1_4.first_page"]["showpage"]
        pcount = p_data["1_4.first_page"]["pcount"]
        if showpage:
            for item in showpage.split(";"):
                matObj = re.search(r"ShowPage\('(\d+)','([^']+)',", item)
                if not matObj:
                    continue
                pageTotal = math.ceil(int(matObj.group(1)) / 10)
                CurDBCode = matObj.group(2)
                result.code_dicts["1_4"][CurDBCode] = {"params": {"curdbcode": CurDBCode}, "max_page": pageTotal}

    result.befor_dicts.update["article_info_json"] = json.dumps(article_info_dict, ensure_ascii=False)
    return result


def cnkijournal_cnkiclasshome_callback(callmodel: CallBackModel[JournalHomeModel]) -> DealModel:
    result = DealModel()
    para_dicts = callmodel.para_dicts
    task_info = callmodel.redis_all.parse_dict["1_1"].task_info
    info_dicts = {"task_name": callmodel.sql_model.task_name,
                  "task_tag": callmodel.sql_model.task_tag,
                  "sub_db_id": callmodel.sql_model.sub_db_id,
                  "task_tag_next": task_info.task_tag_next}
    start_code = ""
    start_name = ""
    for k, v in para_dicts["data"].items():
        if k == "1_1":
            d_i_model = DealInsertModel()
            d_i_model.insert_pre = CoreSqlValue.insert_ig_it
            for item in v["data"]["children"]:
                temp = info_dicts.copy()
                count = item["text"]
                sub_count = re.findall(".*\((.*?)\).*", count)
                onclick = item["onclick"]
                sub = re.findall("Submit.naviSearch\('1','168专题代码','(.*?)','(.*?)'\)", onclick)
                if sub:
                    new_dict2 = {}
                    code = sub[0][0]
                    name = sub[0][1]

                    if len(code) == 1:
                        temp["task_tag"] = temp["task_tag_next"].split(";")[-1]
                        start_code = code
                        start_name = name
                        new_dict2["field"] = name
                        new_dict2["number"] = sub_count[0]
                    else:
                        if code.startswith(start_code):
                            temp["task_tag"] = temp["task_tag_next"].split(";")[0]
                            new_dict2["his"] = "->".join([start_name, name])
                            new_dict2["field"] = name
                            new_dict2["number"] = sub_count[0]
                        else:
                            raise Exception("理论上不应该出现这种情况")

                    temp["page"] = math.ceil(int(sub_count[0]) / 21)
                    temp["home_rawid"] = code
                    temp["home_json"] = json.dumps(new_dict2, ensure_ascii=False)
                del temp["task_tag_next"]
                d_i_model.lists.append(temp)
            result.befor_dicts.insert.append(d_i_model)
    return result


def cnkiqkhome_callback(value):
    result = ""

    result_raw = result
    result = BaseUrl.urlQuery2Dict(value)
    if isinstance(result, dict) and "baseid" in result.keys():
        result = result["baseid"]
    elif result_raw.find("index"):
        result = result_raw.split("/")[-1]
    else:
        result = ""
    return result


def cnkijournal_cnkiqkclasshome_callback(callmodel: CallBackModel[JournalHomeModel]) -> DealModel:
    result = DealModel()
    para_dicts = callmodel.para_dicts
    task_info = callmodel.redis_all.parse_dict["1_1"].task_info
    info_dicts = {"task_name": callmodel.sql_model.task_name,
                  "task_tag": callmodel.sql_model.task_tag,
                  "sub_db_id": callmodel.sql_model.sub_db_id,
                  "task_tag_next": task_info.task_tag_next}
    if "1_1" in para_dicts["data"]:
        data = para_dicts["data"]["1_1"]
        total = data["lblCount"]
        total_page = math.ceil(int(total) / 20) - 1
        result.code_dicts = {
            "1_1": {"max_page": total_page}
        }
        page_index = int(callmodel.sql_model.page_index)
        turn_page = task_info.turn_page
        if (turn_page == 7 and page_index < 3) or (turn_page == 8 and page_index < 4):
            sql_dict = callmodel.sql_model.dict()
            tmp_list = [
                {
                    "key": "task_name",
                    "value": sql_dict["task_name"],
                    "operator": "=",
                    "description": "and"
                },
                {
                    "key": "task_tag",
                    "value": sql_dict["task_tag"],
                    "operator": "=",
                    "description": "and"
                },
                {
                    "key": "home_rawid",
                    "value": sql_dict["home_rawid"],
                    "operator": "=",
                    "description": "and"
                },
                {
                    "key": "page_index",
                    "value": total_page,
                    "operator": ">",
                    "description": "and"
                }
            ]
            du_model_bef_1 = DealUpdateModel()
            du_model_bef_1.update.update({"is_active": "0"})
            list_op = []
            for item in tmp_list:
                op = OperatorSqlModel()
                list_op.append(op.parse_obj(item))
            du_model_bef_1.where = list_op
            result.befor_dicts.update_list.append(du_model_bef_1)
            tmp_list[-1]["operator"] = "<="
            du_model_bef_2 = DealUpdateModel()
            du_model_bef_2.update.update({"is_active": "1"})
            list_op1 = []
            for item in tmp_list:
                op = OperatorSqlModel()
                list_op1.append(op.parse_obj(item))
            du_model_bef_2.where = list_op1
            result.befor_dicts.update_list.append(du_model_bef_2)

            di_model_bef = DealInsertModel()
            di_model_bef.insert_pre = CoreSqlValue.insert_ig_it
            sql_dict.pop("id")
            sql_dict.pop("update_time")
            sql_dict.pop("create_time")
            sql_dict.pop("null_dicts")
            sql_dict.pop("err_msg")
            sql_dict.pop("other_dicts")
            sql_dict.pop("state")
            sql_dict.pop("failcount")
            for page in range(page_index, total_page + 1):
                sql_dict["page_index"] = page
                di_model_bef.lists.append(sql_dict.copy())
            result.befor_dicts.insert.append(di_model_bef)
        di_model_next = DealInsertModel()
        di_model_next.insert_pre = CoreSqlValue.insert_ig_it
        for item in data["value"]["children"]:
            result.befor_dicts.update.update({'page': total_page})
            qk_name = item['qkname'].strip()
            if len(qk_name) != 0:
                organSpan = item['organSpan'].strip()
                fhfactorSpan = item['fhfactorSpan']
                zhfactorSpan = item['zhfactorSpan']
                bztimes = item['bztimes']
                flag = item['flag']
                pykm = item["pykm"]
                journal_rawid = cnkiqkhome_callback(pykm)
                new_dict = {}
                subject_forward = json.loads(callmodel.sql_model.home_json)
                subject = BaseDicts().is_dict_exit_key(subject_forward, "his")
                if subject != "":
                    special_name = subject.split("->")[0]
                    subject_name = BaseDicts().is_dict_exit_key(subject_forward, "field")
                else:
                    special_name = BaseDicts().is_dict_exit_key(subject_forward, "field")
                    subject_name = ""
                new_dict["publisher"] = organSpan
                new_dict["cnki_impact_fh"] = fhfactorSpan
                new_dict["cnki_impact_zh"] = zhfactorSpan
                new_dict["bztimes"] = bztimes
                new_dict["flag"] = flag
                new_dict["special_name"] = special_name
                new_dict["subject_name"] = subject_name

                temp_info = info_dicts.copy()
                task_tag_next = temp_info["task_tag_next"]
                temp_info["task_tag"] = task_tag_next
                del temp_info["task_tag_next"]
                temp_info["journal_rawid"] = journal_rawid
                temp_info["is_active"] = "1"
                temp_info["journal_json"] = json.dumps(new_dict, ensure_ascii=False)
                di_model_next.lists.append(temp_info)
                du_model = DealUpdateModel()
                # du_model.update_no_placeholder.update({"subject": f'CONCAT(`subject`,";{field}")'})
                du_model.update.update({"journal_json": json.dumps(new_dict, ensure_ascii=False),
                                        "sub_db_id": "00002",
                                        "is_active": "1"})
                du_model.where.update({"journal_rawid": journal_rawid,
                                       "task_tag": temp_info["task_tag"],
                                       "task_name": callmodel.sql_model.task_name,
                                       "is_active": "0"})
                result.next_dicts.update_list.append(du_model)
        result.next_dicts.insert.append(di_model_next)
    return result


def cnkijournal_cnkiqkhome_callback(callmodel: CallBackModel[JournalHomeModel]) -> DealModel:
    result = DealModel()
    para_dicts = callmodel.para_dicts
    home_json = json.loads(callmodel.sql_model.home_json)
    his = home_json["his"]
    task_info = callmodel.redis_all.parse_dict["1_1"].task_info
    info_dicts = {"task_name": callmodel.sql_model.task_name,
                  "task_tag": callmodel.sql_model.task_tag,
                  "sub_db_id": callmodel.sql_model.sub_db_id,
                  "task_tag_next": task_info.task_tag_next}
    if "1_1" in para_dicts["data"]:
        data = para_dicts["data"]["1_1"]
        total = data["lblCount"]
        total_page = math.ceil(int(total) / 20) - 1
        result.code_dicts = {
            "1_1": {"max_page": total_page}
        }
        page_index = int(callmodel.sql_model.page_index)
        turn_page = task_info.turn_page
        if (turn_page == 7 and page_index < 3 ) or  (turn_page == 8 and page_index < 4):
            sql_dict = callmodel.sql_model.dict()
            tmp_list = [
                {
                "key":"task_name",
                "value":sql_dict["task_name"],
                "operator" : "=",
                "description":"and"
                },
                {
                    "key": "task_tag",
                    "value": sql_dict["task_tag"],
                    "operator": "=",
                    "description": "and"
                },
                {
                    "key": "home_rawid",
                    "value": sql_dict["home_rawid"],
                    "operator": "=",
                    "description": "and"
                },
                {
                    "key": "page_index",
                    "value": total_page,
                    "operator": ">",
                    "description": "and"
                }
            ]
            du_model_bef_1 = DealUpdateModel()
            du_model_bef_1.update.update({"is_active": "0"})
            list_op = []
            for item in tmp_list:
                op = OperatorSqlModel()
                list_op.append(op.parse_obj(item))
            du_model_bef_1.where = list_op
            result.befor_dicts.update_list.append(du_model_bef_1)
            tmp_list[-1]["operator"] = "<="
            du_model_bef_2 = DealUpdateModel()
            du_model_bef_2.update.update({"is_active": "1"})
            list_op1 = []
            for item in tmp_list:
                op = OperatorSqlModel()
                list_op1.append(op.parse_obj(item))
            du_model_bef_2.where = list_op1
            result.befor_dicts.update_list.append(du_model_bef_2)

            di_model_bef = DealInsertModel()
            di_model_bef.insert_pre = CoreSqlValue.insert_ig_it
            sql_dict.pop("id")
            sql_dict.pop("update_time")
            sql_dict.pop("create_time")
            sql_dict.pop("null_dicts")
            sql_dict.pop("err_msg")
            sql_dict.pop("other_dicts")
            sql_dict.pop("state")
            sql_dict.pop("failcount")
            for page in range(page_index, total_page + 1):
                sql_dict["page_index"] = page
                di_model_bef.lists.append(sql_dict.copy())
            result.befor_dicts.insert.append(di_model_bef)
        di_model_next = DealInsertModel()
        di_model_next.insert_pre = CoreSqlValue.insert_ig_it
        for item in data["value"]["children"]:
            result.befor_dicts.update.update({'page': total_page})
            qk_name = item['qkname'].strip()
            if len(qk_name) != 0:
                organSpan = item['organSpan'].strip()
                fhfactorSpan = item['fhfactorSpan']
                zhfactorSpan = item['zhfactorSpan']
                bztimes = item['bztimes']
                flag = item['flag']
                pykm = item["pykm"]
                journal_rawid = cnkiqkhome_callback(pykm)
                new_dict = {}
                subject_forward = json.loads(callmodel.sql_model.home_json)
                subject = BaseDicts().is_dict_exit_key(subject_forward, "his")
                if subject != "":
                    special_name = subject.split("->")[0]
                    subject_name = BaseDicts().is_dict_exit_key(subject_forward, "field")
                else:
                    special_name = BaseDicts().is_dict_exit_key(subject_forward, "field")
                    subject_name = ""
                new_dict["publisher"] = organSpan
                new_dict["cnki_impact_fh"] = fhfactorSpan
                new_dict["cnki_impact_zh"] = zhfactorSpan
                new_dict["bztimes"] = bztimes
                new_dict["flag"] = flag
                new_dict["special_name"] = special_name
                new_dict["subject_name"] = subject_name

                temp_info = info_dicts.copy()
                task_tag_next = temp_info["task_tag_next"]
                temp_info["task_tag"] = task_tag_next
                del temp_info["task_tag_next"]
                temp_info["journal_rawid"] = journal_rawid
                temp_info["is_active"] = "1"
                temp_info["journal_json"] = json.dumps(new_dict, ensure_ascii=False)
                di_model_next.lists.append(temp_info)
                du_model = DealUpdateModel()
                du_model.update_no_placeholder.update({"subject": f'CONCAT(`subject`,";{his}")'})
                du_model.update.update({"journal_json": json.dumps(new_dict, ensure_ascii=False),
                                        "sub_db_id": "00002",
                                        "is_active": "1"})
                du_model.where.update({"journal_rawid": journal_rawid,
                                       "task_tag": temp_info["task_tag"],
                                       "task_name": callmodel.sql_model.task_name,
                                       "is_active": "0"})
                result.next_dicts.update_list.append(du_model)
        result.next_dicts.insert.append(di_model_next)
    return result
